
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_book/constant/color.dart';

class CommonWidget{

  static CommonWidget? _commonWidget;
  static CommonWidget init(){
    if(_commonWidget==null){
      _commonWidget= CommonWidget();
    }
    return _commonWidget!;
  }


  //获取用户的头像-直径
  Widget getUserImage(String? imageUrl, double diameter) {
    if (imageUrl == null || imageUrl == "") {
      imageUrl = "http://pic.netbian.com/uploads/allimg/201220/220540-16084731404798.jpg";
    }
    return ClipRRect(
      borderRadius: BorderRadius.circular(diameter / 2),
      child: CachedNetworkImage(
        height: diameter,
        width: diameter,
        imageUrl: imageUrl == null ? "" : imageUrl,
        fit: BoxFit.cover,
        placeholder: (context, url) => Container(
          color: AppColor.bgWhite,
        ),
        errorWidget: (context, url, error) => Container(
          color: AppColor.bgWhite,
        ),
      ),
    );
  }


}